# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
import sys


class Solution(object):
    def getMinimumDifference(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        self.maxs = sys.maxsize
        self.a = []
        self.help(root)
        for i in range(1, len(self.a)):
            val = abs(self.a[i] - self.a[i - 1])
            self.maxs = min(self.maxs, val)
        return self.maxs

    def help(self, node):
        if not node:
            return None
        self.help(node.left)
        self.a.append(node.val)
        self.help(node.right)
        return 0

